package com.lang.downloader.http.exception;

import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;

public class HttpDownloadException extends RuntimeException {

    public HttpDownloadException(String message) {
        super("下载异常:" + message);
    }

    public HttpDownloadException(String message, Throwable cause) {
        super("下载异常:" + message, cause);
    }

    public HttpDownloadException(Throwable cause) {
        Class<? extends Throwable> exceptionType = cause.getClass();
        if (NoSuchAlgorithmException.class.isAssignableFrom(exceptionType)) {
            throw new HttpDownloadException("没有这种算法/程序", cause);
        } else if (KeyManagementException.class.isAssignableFrom(exceptionType)) {
            throw new HttpDownloadException("秘钥信息异常", cause);
        } else {
            throw new HttpDownloadException("未知异常", cause);
        }
    }
}
